package com.itheima.controller;

import com.itheima.domain.Member;
import com.itheima.service.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 会员管理接口
 * @Author: hsp
 * @Date: 2022/11/17-11-17-11:15
 * @Description: com.itheima.controller
 * @version: 1.0.0
 */
@RestController
@RequestMapping("/admin/member")
public class MemberController {

    @Resource
    private MemberService memberService;

    //查询会员列表
    @GetMapping("/findAll")
    public List<Member> findAll() {
        return memberService.findAll();
    }

    @PostMapping("/save")
    public void save(@RequestBody Member member) {
        if (member.getId() == null){
            //添加会员
            memberService.save(member);
        }else {
            //修改会员
            memberService.update(member);
        }
    }

    //根据id查询会员列表
    @GetMapping("/findById")
    public Member findById (Integer id){
        return memberService.findById(id);
    }

    //根据id删除单个会员
    @GetMapping("/deleteById")
    public void deleteById (Integer id){
        memberService.deleteById(id);
    }

    //根据id批量删除会员
    @GetMapping("/deleteByIds")
    public void deleteByIds(Integer[] ids){
        memberService.deleteByIds(ids);
    }



}
